<template>
  <el-row>
    <el-row>
      <div style="width:100%;height:15px;padding:5px 5px 5px 10px;">
        <el-breadcrumb separator-class="el-icon-arrow-right">
          <el-breadcrumb-item :to="{ path: '/' }">
            <b style="font-size:16px;">书友网</b>
          </el-breadcrumb-item>
          <el-breadcrumb-item>
            <span style="font-size:16px;">登陆页面</span>
          </el-breadcrumb-item>
        </el-breadcrumb>
      </div>
    </el-row>
    <el-row>
      <el-card>
        <div style="width:50%;margin:auto">
          <el-avatar src="https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png"></el-avatar>
          <el-divider>
            <i class="el-icon-mobile-phone"></i>
          </el-divider>
          <el-form
            :model="ruleForm"
            status-icon
            :rules="rules"
            ref="ruleForm"
            label-width="100px"
            class="demo-ruleForm"
          >
            <el-form-item label="账号" prop="username">
              <el-input
                type="username"
                v-model="ruleForm.username"
                autocomplete="off"
                placeholder="输入账号/邮箱"
              ></el-input>
            </el-form-item>
            <el-form-item label="密码" prop="pass">
              <el-input type="password" v-model="ruleForm.pass" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label align="left">
              <el-checkbox v-model="checked">记住我</el-checkbox>
            </el-form-item>
          </el-form>
          <el-button
            style="letter-spacing:20px;text-indent: 20px;font:16px Medium;"
            type="primary"
            @click="submitForm('ruleForm')"
          >登陆</el-button>
          <p style="text-align:right">
            <el-link style="text-decoration:underline">忘记密码?</el-link>
          </p>
        </div>
      </el-card>
    </el-row>
  </el-row>
</template>

<script>
export default {
  name: "user-login-page",
  data() {
    var validatePass = (rule, value, callback) => {
      if (value === "") {
        callback(new Error("请输入密码"));
      } else {
        if (this.ruleForm.checkPass !== "") {
          this.$refs.ruleForm.validateField("checkPass");
        }
        callback();
      }
    };
    return {
      checked: false,
      ruleForm: {
        username: "",
        pass: ""
      },
      rules: {
        username: [{ required: true, message: "请输入账号", trigger: "blur" }],
        pass: [{ required: true, validator: validatePass, trigger: "blur" }]
      }
    };
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          // alert("submit!");
          localStorage.setItem("token", "18790915572");
          this.$router.push({path:'/'})
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    }
  }
};
</script>

<style>
</style>